<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;

class TruncateImportVchan extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'TruncateImportVchan:tables {--table=}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
        if ($tableName = $this->option('table')) {
            DB::table($tableName)->truncate();
        } else {
            // 直播媒资
            DB::table('vchans')->truncate();
            // 直播归类
            DB::table('vccats')->truncate();
            // 直播分类
            DB::table('vccattags')->truncate();
            // 直播频道流
            DB::table('vcstreams')->truncate();
            // EPG信息
            DB::table('vepgs')->truncate();
            // 直播海报
            DB::table('vcposters')->truncate();
            // 地区(直播媒资)
            DB::table('vcareacats')->truncate();
            // 直播媒资-服务商
            DB::table('vchan_sps')->truncate();
            // 直播媒资-地区
            DB::table('vchan_vcareacats')->truncate();
            // 直播媒资-导演
            DB::table('vchan_vccattags')->truncate();
            // 直播媒资-海报
            DB::table('vchan_vcposters')->truncate();
            // 直播媒资-直播流
            DB::table('vchan_vcstreams')->truncate();
            // 直播媒资-EPG
            DB::table('vchan_vepgs')->truncate();
            // 直播媒资-语言
            DB::table('vchan_vlangs')->truncate();
        }
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');
    }
}
